package com.zrwl.poscloud.core.restapi.admin.baseInfo;
import com.zrwl.poscloud.core.annotion.AuthorityVerify.AuthorityVerify;
import com.zrwl.poscloud.core.annotion.OperationLogger.OperationLogger;
import com.zrwl.poscloud.commons.exception.ThrowableUtils;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.validator.group.Delete;
import com.zrwl.poscloud.commons.validator.group.GetList;
import com.zrwl.poscloud.commons.validator.group.Insert;
import com.zrwl.poscloud.commons.validator.group.Update;
import com.zrwl.poscloud.core.restapi.admin.authority.AdminRestApi;
import com.zrwl.poscloud.xo.service.AdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zrwl.poscloud.xo.service.CommentService;
import com.zrwl.poscloud.xo.vo.CommentVO;
/**
 * 事件评论 controller api类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-03-17
 */
@RestController
@Api(value = "事件评论相关接口", tags = {"事件评论相关接口"})
@RequestMapping("/comment")
@Slf4j
public class CommentRestApi {
    @Autowired
    private CommentService commentService;

    @Autowired
    private AdminService adminService;
    @AuthorityVerify
    @ApiOperation(value = "获取事件评论列表", notes = "获取事件评论列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody CommentVO commentVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取事件评论列表: {}", commentVO);
        return ResultUtil.successWithData(commentService.getPageList(commentVO));
    }

    @AuthorityVerify
    @ApiOperation(value = "获取事件评论列表", notes = "获取事件评论列表", response = String.class)
    @PostMapping("/getAllList")
    public String getAllList(@Validated({GetList.class}) @RequestBody CommentVO commentVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取事件评论列表: {}", commentVO);
        return ResultUtil.successWithData(commentService.getAllList(commentVO));
    }

    @AuthorityVerify
    @OperationLogger(value = "新增事件评论")    @ApiOperation(value = "新增事件评论", notes = "新增事件评论", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody CommentVO commentVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("新增事件评论: {}", commentVO);
        return commentService.add(commentVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "修改事件评论")    @ApiOperation(value = "修改事件评论", notes = "修改事件评论", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody CommentVO commentVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("修改事件评论: {}", commentVO);
        commentVO.setOperateAdminUid(adminService.getMe().getUid());
        return commentService.edit(commentVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "删除事件评论")    @ApiOperation(value = "删除事件评论", notes = "删除事件评论", response = String.class)
    @PostMapping("/delete")
    public String delete(@Validated({Delete.class}) @RequestBody CommentVO commentVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("删除事件评论: {}", commentVO);
        return commentService.delete(commentVO);
    }

    @AuthorityVerify
    @ApiOperation(value = "获取事件评论回复数", notes = "获取事件评论回复数", response = String.class)
    @PostMapping("/getRoot")
    public String getRoot(@Validated({GetList.class}) @RequestBody CommentVO commentVO) {
//        ThrowableUtils.checkParamArgument(result);
        log.info("获取回复数: {}", commentVO);
        return ResultUtil.successWithData(commentService.getRoot(commentVO));
    }

    @AuthorityVerify
    @ApiOperation(value = "获取评论回复详情", notes = "获取评论回复详情", response = String.class)
    @PostMapping("/getNext")
    public String getNext(@Validated({GetList.class}) @RequestBody CommentVO commentVO) {
//        ThrowableUtils.checkParamArgument(result);
        log.info("获取回复数: {}", commentVO);
        return ResultUtil.successWithData(commentService.getNext(commentVO));
    }
}
